package com.htj.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.htj.admin.dao.AdminUserDao;
import com.htj.admin.domain.AdminUser;
import com.htj.admin.service.AdminUserServiceInf;
import com.htj.util.DateTimeUtil;
import com.htj.util.UUIDUtil;
import com.htj.vo.PageListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AdminUserServiceImpl implements AdminUserServiceInf {
    @Autowired
    AdminUserDao adminUserDao;

    /**
     * 登录
     * @param loginAct
     * @param loginPwd
     * @return
     */
    @Override
    public AdminUser login(String loginAct, String loginPwd) {
        AdminUser adminUser = adminUserDao.login(loginAct,loginPwd);
        return adminUser;
    }

    /**
     * 绑定邮箱
     *
     * @param id
     * @param email
     * @return
     */
    @Override
    public boolean bindEmail(String id, String email) {
        boolean bool = false;
        int flag = adminUserDao.bindEmail(id,email);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean add(AdminUser adminUser) {
        boolean bool = false;
        String time = DateTimeUtil.getSysTime();
        adminUser.setCreateTime(time);
        int flag = adminUserDao.add(adminUser);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public PageListVo<AdminUser> pageList(Map<String, String> map) {
        PageListVo<AdminUser> pageListVo = new PageListVo<>();
        String currentPage = map.get("currentPage");
        String pageSize = map.get("pageSize");
        PageHelper.startPage(Integer.valueOf(currentPage),Integer.valueOf(pageSize));
        List<AdminUser> list = adminUserDao.pageList(map);
        PageInfo<AdminUser> pageInfo = new PageInfo<>(list);
        List<AdminUser> pageInfoList = pageInfo.getList();
        int total = (int) pageInfo.getTotal();
        pageListVo.setList(pageInfoList);
        pageListVo.setTotal(total);
        return pageListVo;
    }

    @Override
    public boolean update(AdminUser adminUser) {
        boolean bool = false;
        int flag = adminUserDao.update(adminUser);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean delete(Integer id) {
        boolean bool = false;
        int flag = adminUserDao.delete(id);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean changeStatus(Map<String, Integer> map) {
        boolean bool = false;
        int flag = adminUserDao.changeStatus(map);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public AdminUser getUserById(String id) {
        AdminUser adminUser = adminUserDao.getUserById(id);
        return adminUser;
    }
}
